using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class PlayerCatchSwordState : PlayerState
{
    private Transform sword;
    public PlayerCatchSwordState(Player _player, PlayerStateMachine _stateMachine, string _animBoolName) : base(_player, _stateMachine, _animBoolName)
    {
    }

    public override void Enter()
    {
        base.Enter();
        sword = player.sword.transform;
        player.fx.PlayDustFX();// 向后退出现灰尘
        player.fx.ScreenShake(player.fx.shakeSwordImpact);// 抖动镜头
        // 根据剑的方向转向
        if (player.transform.position.x > sword.position.x && player.facingDir == 1)
        {
            player.Flip();
        }
        else if (player.transform.position.x < sword.position.x && player.facingDir == -1)
        {
            player.Flip();
        }
        // 受到剑的后坐力滑动
        rb.velocity = new Vector2(player.swordReturnImpact * -player.facingDir, rb.velocity.y);
    }

    public override void Exit()
    {
        base.Exit();
        player.StartCoroutine("BusyFor", .1f);// 角色忙
    }

    public override void Update()
    {
        base.Update();
        if (triggerCalled)// 动画结束回到待机状态
        {
            stateMachine.ChangeState(player.idleState);
        }
    }


}
